<?php

class ArticleModel extends Model {
   
    /**
     * 发布日志
     * 数据保存到数据库
     * 
     * @param type $data
     */
    public function addArticle($data) {
        $title = $data['title'];
        $content = $data['content'];
        $addtime = $data['addtime'];
        $catid = $data['catid'];
        $sql = "INSERT INTO s_article (title, content, addtime, catid) VALUES ('{$title}', '{$content}', '{$addtime}', {$catid})";
        $row = $this->execute($sql);
        return $row;
    }
    /**
     * 获取所有的日志
     */
    public function getAllItems() {
        $sql = "SELECT a.*, c.name FROM s_article a LEFT JOIN s_category c ON a.catid = c.id ORDER BY a.id DESC";
        $row = $this->query($sql);
        return $row;
    }
    /**
     * 获取某一条日志的内容
     */
    public function getDetailById($id) {
        $sql = "SELECT a.*, c.name FROM s_article a LEFT JOIN s_category c ON a.catid = c.id WHERE a.id = {$id}";
        $row = $this->query($sql, FALSE);
        return $row;
    }
}
